package com.example.user.myhjjf_app.presenter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.InfoWindow;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.example.user.myhjjf_app.R;
import com.example.user.myhjjf_app.model.Model_Regional;
import com.example.user.myhjjf_app.model.Model_Tagging;
import com.example.user.myhjjf_app.view.Acitvity_edit;
import com.example.user.myhjjf_app.view.Activity_District;
import com.example.user.myhjjf_app.view.Activity_Tagging;

import java.io.DataInput;
import java.io.Serializable;

/**
 * Created by User on 2017/8/21.
 */

public class Presenter_Tagging {
    LatLng latLng;
    Model_Tagging model_tagging;
    Bundle bundle;
    LatLng latLng1;
    Context contet;
    BitmapDescriptor bitmap = null;
    public Presenter_Tagging(Model_Tagging model_tagging, Context context){
        this.model_tagging = model_tagging;
        this.contet = context;
        LatLng latLng = null;
         latLng1 = new LatLng(model_tagging.getValue().getItem().getLat(),model_tagging.getValue().getItem().getLng());
        for (int i = 0; i < model_tagging.getValue().getArray().size(); i++) {
            double lng = model_tagging.getValue().getArray().get(i).getLng();
            double lat = model_tagging.getValue().getArray().get(i).getLat();
            latLng = new LatLng(lat,lng);
            this.latLng = latLng;
            int type = model_tagging.getValue().getArray().get(i).getType();
            if (type==1){
                bitmap = BitmapDescriptorFactory.fromResource(R.mipmap.icon_site);
            }else if (type==2){
                bitmap = BitmapDescriptorFactory.fromResource(R.mipmap.gjx);
            }else if (type==3){
                bitmap = BitmapDescriptorFactory.fromResource(R.mipmap.fgx);
            }
            bundle = new Bundle();
            bundle.putSerializable("data", (Serializable) model_tagging.getValue().getArray());
            View view = LayoutInflater.from(context).inflate(R.layout.lisstitem_tagging,null);
            TextView textView = view.findViewById(R.id.baidumap_custom_text);
            ImageView imageView = view.findViewById(R.id.baidumap_custom_img);
            textView.setText(model_tagging.getValue().getArray().get(i).getName());
            imageView.setImageBitmap(bitmap.getBitmap());
            addView(bundle,view,latLng);
        }
        if (latLng!=null){
            Activity_Tagging.baiduMap.setMapStatus(MapStatusUpdateFactory.newLatLngZoom(this.latLng,17));
        }else {
            Activity_Tagging.baiduMap.setMapStatus(MapStatusUpdateFactory.newLatLngZoom(this.latLng1,17));
        }

    }
    public void addView(Bundle bundle,View view,LatLng latLng){
        OverlayOptions option = new MarkerOptions()
                .position(latLng)
                .extraInfo(bundle)
                .icon(BitmapDescriptorFactory.fromView(view));
        Activity_Tagging.baiduMap.addOverlay(option);
    }

}
